package com.woniuxy.controller;


import com.woniuxy.commons.annotation.RuleValidate;
import com.woniuxy.controller.form.AccountPageForm;
import com.woniuxy.controller.form.ChaneAccountPasswordForm;
import com.woniuxy.controller.form.RegistAccountForm;
import com.woniuxy.controller.info.Result;
import com.woniuxy.model.Account;
import com.woniuxy.service.AccountService;
import com.woniuxy.util.exception.ParameterException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-15
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("getAccountPages")
    public Result getAccountPages( AccountPageForm accountPageForm){
        return accountService.getAccountPages(accountPageForm);
    }

    @PostMapping("changPassword")
    public Result changPassword( @RequestBody ChaneAccountPasswordForm chaneAccountPasswordForm){
        return accountService.changPassword(chaneAccountPasswordForm);
    }
    @RuleValidate
    @PostMapping("addAccount")
    public Result addAccount(@RequestBody  RegistAccountForm registAccountForm){
//        if(bindingResult.hasErrors()){
//            throw new ParameterException();
//        }
//        accountName
        return accountService.addAccount(registAccountForm);
    }

}

